import pickle
import random
import os

grades=["金","紫","蓝"]
allkachi={"金":["涵露(角色)(冰)","流璃(角色)(雷)","希郂(角色)(岩)","禾熙(角色)(量子)"],
"紫":["潇茸(角色)(火)","利依(角色)(草)"],
"蓝":["银怀表(遗器)(道具)","手帕(遗器)(道具)"]}
zhandoudirenchi=["反重子","量子织叶者"]



#bag.pkl
# 定义文件路径和默认列表
pkl_file = "bag.pkl"
default_list = ["开拓者(角色)(物理)","银怀表(遗器)(道具)"]  # 默认列表 [int0, int1]

# 检查文件是否存在，不存在则创建
if not os.path.exists(pkl_file):
    with open(pkl_file, "wb") as f:
        pickle.dump(default_list, f)

#lhcoin.pkl
# 定义文件路径
pkl_file = "lhcoin.pkl"
default_value=0 # 默认值

# 检查文件是否存在，如果不存在则创建
if not os.path.exists(pkl_file):
    with open(pkl_file, "wb") as f:
        pickle.dump(default_value, f)
    
#slyz.pkl
# 定义文件路径
pkl_file = "slyz.pkl"
default_value=0 # 默认值

# 检查文件是否存在，如果不存在则创建
if not os.path.exists(pkl_file):
    with open(pkl_file, "wb") as f:
        pickle.dump(default_value, f)



with open("bag.pkl","rb")as file:#导入变量
    bag=pickle.load(file)
with open("lhcoin.pkl","rb")as file:
    lhcoin=pickle.load(file)
with open("slyz.pkl","rb")as file:
    slyz=pickle.load(file)

print("\033[36m欢迎来到游戏！\033[0m")
print("提示：","\033[4;37;41m退出时请务必选择3键退出，\n不要直接点击停止运行或关闭!!!!!\n造成物品丢失作者概不负责\033[0m")
while True:
    q=input("系统：请选择\n1:抽卡\n2:战斗\n3:退出\n4:兑换\n5:查询\n6:角色\n你：")
    if q=="1":
        q=input("系统：请选择抽卡活动\n1:群星抽卡\n2:水润万物\n你：")
        if q=="1":
            q=input("系统：\n1:单抽(闪亮缘座×1)\n2:十抽(闪亮缘座×9)\n你：")
            if q=="1":
                if slyz>=1:
                    slyz-=1
                    rg=(random.choices(grades,(0.25,29.75,70),k=1))[0]
                    rc=(random.choice(allkachi[rg]))
                    a=rc
                    print(rg,"-",rc)
                    bag.append(a)
                    continue
                else:
                    print("闪亮缘座不足")
                    continue
            if q=="2":
                if slyz>=9:
                    slyz-=9
                    for i in range(10):
                        rg=(random.choices(grades,(1,29,70),k=1))[0]
                        rc=(random.choice(allkachi[rg]))
                        a=rc
                        print(rg,"-",rc)
                        bag.append(a)
                    continue
                else:
                    print("闪亮缘座不足")
                    continue
        if q=="2":
            print("该卡池暂未开放哦！")
            continue
    if q=="2":
        diren=(random.choice(zhandoudirenchi))
        print("你的敌人是{}".format(diren))
        direnh=int(random.randint(300,380))
        ph=320
        zhanjidian=2
        print("敌人{0}血\n你{1}血".format(direnh,ph))
        js=(input("系统：请选择你上场的角色，输入字母为取消战斗，你有{}\n(请输入第几个角色)\n你：".format(bag)))
        if js.isalpha()==True:
            continue
        if js.isdigit()==True:
            jss=int(js)-1
            v=bag[-1]
            g=bag.index(v)
            if not jss>g:
                a=(bag[jss])
                print(a)
                if a=="涵露(角色)(冰)":
                    while not direnh<=0 or not ph<=0:
                        if diren=="反重子":
                            print("普攻:冰锥刺晶 战技:环冰射线")
                            s=input("普攻:Q 战技:E\n你：")
                            if s=="q" and zhanjidian<5:
                                direnh-=18
                                zhanjidian+=1
                                print("敌人-18(冰)")
                                print("你{}\n敌{}\n战技点{}".format(ph,direnh,zhanjidian))
                            if s=="q" and zhanjidian>=5:
                                direnh-=18
                                print("敌人-18(冰)")
                            if s=="e" and zhanjidian>0:
                                direnh-=36
                                zhanjidian-=1
                                print("敌人-36(冰)")
                                print("你{}\n敌{}\n战技点{}".format(ph,direnh,zhanjidian))
                            if s=="e" and zhanjidian<=0:
                                print("你没有战技点了！\n已改为普攻")
                                direnh-=18
                                zhanjidian+=1
                                print("敌人-18(冰)")
                                print("你{}\n敌{}\n战技点{}".format(ph,direnh,zhanjidian))
                            k=random.randint(1,2)
                            if k==1:
                                ph-=16
                                print("你-16(物理)")
                                print("你{}\n敌{}\n战技点{}".format(ph,direnh,zhanjidian))
                            if k==2:
                                ph-28
                                print("你-28(量子)")
                                print("你{}\n敌{}\n战技点{}".format(ph,direnh,zhanjidian))
                            if direnh<=0 or ph<=0:
                                break
                        if diren=="量子织叶者":
                            print("普攻:冰锥刺晶 战技:环冰射线")
                            s=input("普攻:Q 战技:E\n你：")
                            if s=="q" and zhanjidian<5:
                                direnh-=18
                                zhanjidian+=1
                                print("敌人-18(冰)")
                                print("你{}\n敌{}\n战技点{}".format(ph,direnh,zhanjidian))
                            if s=="q" and zhanjidian>=5:
                                direnh-=18
                                print("敌人-18(冰)")
                            if s=="e" and zhanjidian>0:
                                direnh-=36
                                zhanjidian-=1
                                print("敌人-36(冰)")
                                print("你{}\n敌{}\n战技点{}".format(ph,direnh,zhanjidian))
                            if s=="e" and zhanjidian<=0:
                                print("你没有战技点了！\n已改为普攻")
                                direnh-=18
                                zhanjidian+=1
                                print("敌人-18(冰)")
                                print("你{}\n敌{}\n战技点{}".format(ph,direnh,zhanjidian))
                            k=random.randint(1,2)
                            if k==1:
                                ph-=20
                                print("你-20(量子)")
                                print("你{}\n敌{}\n战技点{}".format(ph,direnh,zhanjidian))
                            if k==2:
                                ph-30
                                print("你-30(量子)")
                                print("你{}\n敌{}\n战技点{}".format(ph,direnh,zhanjidian))
                            if direnh<=0 or ph<=0:
                                break
                    if ph<=0:
                        print("\033[0;35;43m战斗失败\033[0m")
                        continue
                    if direnh<=0:
                        print("\033[0;35;43m结束战斗\033[0m")
                        lhcoin+=1
                        print("灵魂币+1")
                        continue
                if a=="流璃(角色)(雷)":
                    while not direnh<=0 or not ph<=0:
                        if diren=="反重子":
                            print("普攻:雷霹刃 战技:落雷")
                            s=input("普攻:Q 战技:E\n你：")
                            if s=="q" and zhanjidian<5:
                                direnh-=15
                                zhanjidian+=1
                                print("敌人-15(物理)")
                                print("你{}\n敌{}\n战技点{}".format(ph,direnh,zhanjidian))
                            if s=="q" and zhanjidian>=5:
                                direnh-=15
                                print("敌人-15(物理)")
                            if s=="e" and zhanjidian>0:
                                direnh-=40
                                zhanjidian-=1
                                print("敌人-40(雷)")
                                print("你{}\n敌{}\n战技点{}".format(ph,direnh,zhanjidian))
                            if s=="e" and zhanjidian<=0:
                                print("你没有战技点了！\n已改为普攻")
                                direnh-=15
                                zhanjidian+=1
                                print("敌人-15(物理)")
                                print("你{}\n敌{}\n战技点{}".format(ph,direnh,zhanjidian))
                            k=random.randint(1,2)
                            if k==1:
                                ph-=16
                                print("你-16(物理)")
                                print("你{}\n敌{}\n战技点{}".format(ph,direnh,zhanjidian))
                            if k==2:
                                ph-28
                                print("你-28(量子)")
                                print("你{}\n敌{}\n战技点{}".format(ph,direnh,zhanjidian))
                            if direnh<=0 or ph<=0:
                                break
                        if diren=="量子织叶者":
                            print("普攻:雷霹刃 战技:落雷")
                            s=input("普攻:Q 战技:E\n你：")
                            if s=="q" and zhanjidian<5:
                                direnh-=15
                                zhanjidian+=1
                                print("敌人-15(物理)")
                                print("你{}\n敌{}\n战技点{}".format(ph,direnh,zhanjidian))
                            if s=="q" and zhanjidian>=5:
                                direnh-=15
                                print("敌人-15(物理)")
                            if s=="e" and zhanjidian>0:
                                direnh-=40
                                zhanjidian-=1
                                print("敌人-40(雷)")
                                print("你{}\n敌{}\n战技点{}".format(ph,direnh,zhanjidian))
                            if s=="e" and zhanjidian<=0:
                                print("你没有战技点了！\n已改为普攻")
                                direnh-=15
                                zhanjidian+=1
                                print("敌人-15(物理)")
                                print("你{}\n敌{}\n战技点{}".format(ph,direnh,zhanjidian))
                            k=random.randint(1,2)
                            if k==1:
                                ph-=20
                                print("你-20(量子)")
                                print("你{}\n敌{}\n战技点{}".format(ph,direnh,zhanjidian))
                            if k==2:
                                ph-30
                                print("你-30(量子)")
                                print("你{}\n敌{}\n战技点{}".format(ph,direnh,zhanjidian))
                            if direnh<=0 or ph<=0:
                                break
                    if ph<=0:
                        print("\033[0;35;43m战斗失败\033[0m")
                        continue
                    if direnh<=0:
                        print("\033[0;35;43m结束战斗\033[0m")
                        lhcoin+=1
                        print("灵魂币+1")
                        continue
                if a=="开拓者(角色)(物理)":
                    while not direnh<=0 or not ph<=0:
                        if diren=="反重子":
                            print("普攻:再见安打 战技:安息全垒打")
                            s=input("普攻:Q 战技:E\n你：")
                            if s=="q" and zhanjidian<5:
                                direnh-=20
                                zhanjidian+=1
                                print("敌人-20(物理)")
                                print("你{}\n敌{}\n战技点{}".format(ph,direnh,zhanjidian))
                            if s=="q" and zhanjidian>=5:
                                direnh-=20
                                print("敌人-20(物理)")
                            if s=="e" and zhanjidian>0:
                                direnh-=33
                                zhanjidian-=1
                                print("敌人-33(物理)")
                                print("你{}\n敌{}\n战技点{}".format(ph,direnh,zhanjidian))
                            if s=="e" and zhanjidian<=0:
                                print("你没有战技点了！\n已改为普攻")
                                direnh-=20
                                zhanjidian+=1
                                print("敌人-20(物理)")
                                print("你{}\n敌{}\n战技点{}".format(ph,direnh,zhanjidian))
                            k=random.randint(1,2)
                            if k==1:
                                ph-=16
                                print("你-16(物理)")
                                print("你{}\n敌{}\n战技点{}".format(ph,direnh,zhanjidian))
                            if k==2:
                                ph-28
                                print("你-28(量子)")
                                print("你{}\n敌{}\n战技点{}".format(ph,direnh,zhanjidian))
                            if direnh<=0 or ph<=0:
                                break
                        if diren=="量子织叶者":
                            print("普攻:再见安打 战技:安息全垒打")
                            s=input("普攻:Q 战技:E\n你：")
                            if s=="q" and zhanjidian<5:
                                direnh-=20
                                zhanjidian+=1
                                print("敌人-20(物理)")
                                print("你{}\n敌{}\n战技点{}".format(ph,direnh,zhanjidian))
                            if s=="q" and zhanjidian>=5:
                                direnh-=20
                                print("敌人-20(物理)")
                            if s=="e" and zhanjidian>0:
                                direnh-=33
                                zhanjidian-=1
                                print("敌人-33(物理)")
                                print("你{}\n敌{}\n战技点{}".format(ph,direnh,zhanjidian))
                            if s=="e" and zhanjidian<=0:
                                print("你没有战技点了！\n已改为普攻")
                                direnh-=20
                                zhanjidian+=1
                                print("敌人-20(物理)")
                                print("你{}\n敌{}\n战技点{}".format(ph,direnh,zhanjidian))
                            k=random.randint(1,2)
                            if k==1:
                                ph-=20
                                print("你-20(量子)")
                                print("你{}\n敌{}\n战技点{}".format(ph,direnh,zhanjidian))
                            if k==2:
                                ph-30
                                print("你-30(量子)")
                                print("你{}\n敌{}\n战技点{}".format(ph,direnh,zhanjidian))
                            if direnh<=0 or ph<=0:
                                break
                    if ph<=0:
                        print("\033[0;35;43m战斗失败\033[0m")
                        continue
                    if direnh<=0:
                        print("\033[0;35;43m结束战斗\033[0m")
                        lhcoin+=1
                        print("灵魂币+1")
                        continue
                elif "(道具)" in bag[jss]:
                    print("他是道具！！")
                    continue
                else:
                    print("没有该角色")
                    continue
            else:
                print("你输的是什么东西")
                continue
        else:
            continue
    if q=="3":
        with open("slyz.pkl","wb")as file:#导出变量
            pickle.dump(slyz,file)
        with open("bag.pkl","wb")as file:#导出变量
            pickle.dump(bag,file)
        with open("lhcoin.pkl","wb")as file:#导出变量
            pickle.dump(lhcoin,file)
        break
    if q=="4":
        print("2灵魂币=1闪亮缘座")
        c=int(lhcoin/2)
        d=c*2
        b=input("系统：可兑换{}个闪亮缘座，是否兑换？\n1:是 2:否\n你：".format(c))
        if b=="1":
            slyz+=c
            lhcoin-=d
            print("+{}闪亮缘座".format(c))
            continue
    if q=="5":
        a=input("系统：你想查什么？\n1:背包 2:灵魂币 3:闪亮缘座\n你：")
        if a=="1":
            print(bag)
            a=input("系统：执行什么操作？\n1:退出\n2:删除单个\n3:删除全部\n4:删除筛选内容\n你：")
            if a=="1":
                continue
            if a=="2":
                print(bag)
                s=input("请输入第几个 你：")
                b=input("确定要删除吗？\n1:确定 2:取消\n\033[1;37;41m此操作不可撤销\033[0m\n你：")
                if b=="1":
                    if bag[s]=="开拓者":
                        print("初始角色不能删除")
                        break
                    else:
                        m=(int(s)-1)
                        bag.pop(m)
                if b=="2":
                    break
            continue
        if a=="2":
            print(lhcoin)
            continue
        if a=="3":
            print(slyz)
            continue
        
        
        
        
            